<script setup>
	import { ref, reactive, computed } from 'vue'
	import { onLoad } from "@dcloudio/uni-app"
	import { uniFetch } from '../../utils/fetch';
	const id=ref("")
	onLoad(e => {
		console.log(e);
	id.value=e.id
	})
	const certificatePictureList = ref([]);
	const deliverPictureList = ref([]);
	const enablesubmit=computed(()=>{
		console.log((certificatePictureList.value.length>0&&certificatePictureList.value.length<=3))&&((deliverPictureList.value.length>0&&deliverPictureList.value.length<=3));
		return ((certificatePictureList.value.length>0&&certificatePictureList.value.length<=3))&&((deliverPictureList.value.length>0&&deliverPictureList.value.length<=3))
	})
	
	const submit=()=>{
		console.log(certificatePictureList.value);
		let arr=ref([]);
		let arr1=ref([]);
		certificatePictureList.value.forEach(el=>{
			arr.value.push({
				url:el.url
			})
		})
		deliverPictureList.value.forEach(el=>{
			arr1.value.push({
				url:el.url
			})
		})
		uniFetch({
			url:"/driver/tasks/deliver",
			method:"POST",
			data:{
				id:id.value,
				certificatePictureList:arr.value,
				deliverPictureList:arr1.value
			}
		}).then(res=>{
			console.log(res);
			if(res.data.code == 200){
				uni.showToast({
					title:"操作成功",
					icon:"none"
				})
				uni.reLaunch({
					url:'/subpkg_task/detail/index?id=' + id.value
				})
			}else{
				uni.showToast({
					title:res.data.msg,
					icon:"none"
				})
			}
		})
	}
</script>
<template>
	<view class="page-container">
		<view class="receipt-info">
			<uni-file-picker v-model="certificatePictureList" file-extname="jpg,webp,gif,png" file-mediatype="image" limit="3" title="请拍照上传交付凭证"></uni-file-picker>
			<uni-file-picker v-model="deliverPictureList" file-extname="jpg,webp,gif,png" file-mediatype="image" limit="3" title="请拍照上传交付货品照片"></uni-file-picker>
		</view>
		<button :disabled="!enablesubmit" @click="submit" class="button">提交</button>
	</view>
</template>

<style lang="scss" scoped>
	.page-container {
		padding: 30rpx;
	}

	.receipt-info {
		min-height: 600rpx;
		background-color: #fff;
		padding: 20rpx 30rpx;
		border-radius: 16rpx;

		::v-deep .uni-file-picker {
			margin-bottom: 30rpx;
		}
	}

	.button {
		height: 100rpx;
		text-align: center;
		line-height: 100rpx;
		/* #ifdef APP */
		padding-top: 4rpx;
		/* #endif */
		border-radius: 100rpx;
		margin-top: 60rpx;
		color: #fff;
		font-size: $uni-font-size-big;
		background-color: $uni-primary;

		&[disabled],
		&.disabled {
			color: #fff;
			background-color: #fadcd9;
		}
	}
</style>